package com.lanchetech.merchant.controller;

import com.lanchetech.bean.request.CountByTimeReq;
import com.lanchetech.bean.request.HomeStatisticsReq;
import com.lanchetech.bean.request.SpuSellStatisticsReq;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.merchant.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "统计接口", tags = "统计接口")
@RequestMapping("/api/statistics")
@RestController
public class StatisticsController {

    @Autowired
    StatisticsService statisticsService;


    @ApiOperation("获取首页数据统计")
    @PostMapping("/getDataStatistics")
    public ResultData<MerchantHomeStatisticsVO> getDataStatistics(@RequestBody HomeStatisticsReq req) {
        return statisticsService.getDataStatistics(req);
    }

    @ApiOperation("获取一年中每月销售额统计")
    @GetMapping("/getOrderStatisticsByYear")
    public ResultData<OrderStatisticsVO> getOrderStatisticsByYear(@RequestParam("year") Integer year) {
        return statisticsService.getOrderStatisticsByYear(year);
    }

    @ApiOperation("获取指定商品的统计数据")
    @PostMapping("/getSpuStatistics")
    public ResultData<SpuSellStatisticsVO> getSpuSellStatistics(@RequestBody SpuSellStatisticsReq req) {
        return statisticsService.getSpuSellStatistics(req);
    }

    @ApiOperation(value = "统计指定时间区间的日订单数量（订单状态为已支付、待评论、已完成）")
    @PostMapping("/getOrdersCount")
    public ResultData<List<LongCountByDateVO>> getOrdersCount(@RequestBody CountByTimeReq req) {
        return statisticsService.getOrdersCount(req);
    }

    @ApiOperation(value = "统计指定时间区间的日销售金额（订单状态为已支付、待评论、已完成）")
    @PostMapping("/getPayAmountCount")
    public ResultData<List<BigDecimalCountByDateVO>> getPayAmountCount(@RequestBody CountByTimeReq req) {
        return statisticsService.getPayAmountCount(req);
    }

    @ApiOperation("获取商品销量从高到低排名前10的商品")
    @GetMapping("/getTopSpu")
    public ResultData<List<SpuVO>> getTopSpu() {
        return statisticsService.getTopSpu();
    }
}
